package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.mvp.contract.IPowerContract;

/**
 * Copyright (c)2019
 * author: zdh
 * created on: 2019/1/14 18:12
 * description:
 */
public class HotSearchAdapter extends RecyclerView.Adapter<HotSearchAdapter.HistoryHolder> {

    private Context mContext;
    private ArrayList<String> viewData;


    public interface GhfInterface {
        public void onClick(View view, String data, int position);
    }

    public void GhfOnClick(GhfInterface ghfInterface) {
        this.ghfInterface = ghfInterface;
    }

    private GhfInterface ghfInterface;
    public HotSearchAdapter(Context busSearchHistotyActivity) {
        mContext = busSearchHistotyActivity;

    }

    @Override
    public HistoryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.hot_view, parent, false);
        return new HistoryHolder(view);
    }

    @Override
    public void onBindViewHolder(HistoryHolder holder, final int position) {
        if (viewData != null) {
            holder.historyTv.setText(viewData.get(position));
            if(position==0){
            holder.imageView.setVisibility(View.VISIBLE);
            }
            holder.historyTv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (ghfInterface != null) {
                        ghfInterface.onClick(v,viewData.get(position), position);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return null == viewData ? 0 : viewData.size();
    }

    public void setViewData(ArrayList<String> viewData) {
        this.viewData = viewData;
    }

    public static class HistoryHolder extends RecyclerView.ViewHolder {

        private final TextView historyTv;
        private final ImageView imageView;
        public HistoryHolder(View itemView) {
            super(itemView);
            historyTv = (TextView) itemView.findViewById(R.id.history_tv);
            imageView=(ImageView) itemView.findViewById(R.id.hot_text_label);
        }
    }
}
